What is @aws-cdk/aws-route53?
@aws-cdk/aws-route53 is an AWS Cloud Development Kit (CDK) library that allows you to define and manage Amazon Route 53 resources using code. It provides a high-level, object-oriented abstraction to create and manage DNS zones, records, and other Route 53 features.
What are @aws-cdk/aws-route53's main functionalities?
Create a Hosted Zone
This code sample demonstrates how to create a new hosted zone in Route 53 using the AWS CDK. A hosted zone is a container for DNS records for a specific domain.
const route53 = require('@aws-cdk/aws-route53');
const cdk = require('@aws-cdk/core');
const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack');
const zone = new route53.HostedZone(stack, 'MyHostedZone', {
zoneName: 'example.com',
});
app.synth();
Create an A Record
This code sample demonstrates how to create an A record in a hosted zone. An A record maps a domain name to an IPv4 address.
const route53 = require('@aws-cdk/aws-route53');
const cdk = require('@aws-cdk/core');
const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack');
const zone = new route53.HostedZone(stack, 'MyHostedZone', {
zoneName: 'example.com',
});
new route53.ARecord(stack, 'MyARecord', {
zone,
target: route53.RecordTarget.fromIpAddresses('1.2.3.4'),
});
app.synth();
Create a CNAME Record
This code sample demonstrates how to create a CNAME record in a hosted zone. A CNAME record maps a domain name to another domain name.
const route53 = require('@aws-cdk/aws-route53');
const cdk = require('@aws-cdk/core');
const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack');
const zone = new route53.HostedZone(stack, 'MyHostedZone', {
zoneName: 'example.com',
});
new route53.CnameRecord(stack, 'MyCnameRecord', {
zone,
domainName: 'example.com',
recordName: 'www',
});
app.synth();
Create an Alias Record
This code sample demonstrates how to create an alias record in a hosted zone. An alias record maps a domain name to an AWS resource, such as an Elastic Load Balancer.
const route53 = require('@aws-cdk/aws-route53');
const cdk = require('@aws-cdk/core');
const targets = require('@aws-cdk/aws-route53-targets');
const elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack');
const zone = new route53.HostedZone(stack, 'MyHostedZone', {
zoneName: 'example.com',
});
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', {
vpc,
internetFacing: true,
});
new route53.ARecord(stack, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new targets.LoadBalancerTarget(lb)),
});
app.synth();
Other packages similar to @aws-cdk/aws-route53
aws-sdk
The aws-sdk package is the official AWS SDK for JavaScript. It provides low-level access to all AWS services, including Route 53. Unlike @aws-cdk/aws-route53, which is a high-level abstraction for defining infrastructure as code, aws-sdk requires more detailed and manual configuration.
serverless
The serverless framework allows you to build and deploy serverless applications on AWS and other cloud providers. It includes plugins for managing Route 53 resources. While it provides a higher-level abstraction than aws-sdk, it is not as integrated with infrastructure as code as the AWS CDK.
terraform
Terraform is an open-source infrastructure as code software tool created by HashiCorp. It allows you to define and provision data center infrastructure using a high-level configuration language. Terraform has a provider for AWS, including Route 53 resources. It is similar to AWS CDK in that it allows you to define infrastructure as code, but it uses a different syntax and approach.
AWS Route53 Construct Library
To add a public hosted zone:
import route53 = require('@aws-cdk/aws-route53');
new route53.PublicHostedZone(this, 'HostedZone', {
zoneName: 'fully.qualified.domain.com'
});
To add a private hosted zone, use PrivateHostedZone
. Note that
enableDnsHostnames
and enableDnsSupport
must have been enabled for the
VPC you're configuring for private hosted zones.
import ec2 = require('@aws-cdk/aws-ec2');
import route53 = require('@aws-cdk/aws-route53');
const vpc = new ec2.VpcNetwork(this, 'VPC');
const zone = new route53.PrivateHostedZone(this, 'HostedZone', {
zoneName: 'fully.qualified.domain.com',
vpc
});
Additional VPCs can be added with zone.addVPC()
.
Adding Records
To add a TXT record to your zone:
import route53 = require('@aws-cdk/aws-route53');
new route53.TxtRecord(zone, 'TXTRecord', {
recordName: '_foo',
recordValue: 'Bar!',
ttl: 90,
});
Adding records to existing hosted zones
If you know the ID and Name of a Hosted Zone, you can import it directly:
const zone = HostedZone.import(this, 'MyZone', {
zoneName: 'example.com',
hostedZoneId: 'ZOJJZC49E0EPZ',
});
If you don't know the ID of a Hosted Zone, you can use the HostedZoneProvider
to discover and import it:
const zone = new HostedZoneProvider(this, {
domainName: 'example.com'
}).findAndImport(this, 'MyZone');
0.22.0 (2019-01-10)
This is a major release with multiple breaking changes in the core layers.
Please consult the breaking changes section below for details.
We are focusing these days on finalizing the common patterns and APIs of the CDK
framework and the AWS Construct Library, which is why you are seeing all these
breaking changes. Expect a few more releases with changes of that nature as we
stabilize these APIs, so you might want to hold off with upgrading. We will
communicate when this foundational work is complete.
Bug Fixes
- core: automatic cross-stack refs for CFN resources (#1510) (ca5ee35)
- ecs: correct typo and other minor mistakes in ecs readme (#1448) (9c91b20)
- elbv2: unable to specify load balancer name (#1486) (5b24583), closes #973 #1481
- lambda: use IRole instead of Role to allow imports (#1509) (b909dcd)
- toolkit: fix typo in --rename option description (#1438) (1dd56d4)
- toolkit: support multiple toolkit stacks in the same environment (#1427) (095da14), closes #1416
Features
- apigateway: add tracingEnabled property to APIGW Stage (#1482) (fefa764)
- assets: enable local tooling scenarios such as lambda debugging (#1433) (0d2b633), closes #1432
- aws-cdk: better stack dependency handling (#1511) (b4bbaf0), closes #1508 #1505
- aws-codepipeline: jenkins build and test actions (#1216) (471e8eb)
- aws-codepipeline: support notifications on the ManualApprovalAction (#1368) (068fa46), closes #1222
- aws-ecs: add support Amazon Linux 2 (#1484) (82ec0ff), closes #1483
- aws-kms: allow tagging kms keys (#1485) (f43b4d4)
- aws-lambda: add input and output artifacts to the CodePipeline action (#1390) (fbd7728), closes #1384
- cdk: transparently use constructs from another stack (d7371f0), closes #1324
- cli: allow specifying options using env vars (#1447) (7cd84a0)
- aws resource api linting (breaking changes) (#1434) (8c17ca7), closes #742 #1428
- core: cloudformation condition chaining (#1494) (2169015), closes #1457
- diff: better diff of arbitrary json objects (#1488) (607f997)
- route53: support cname records (#1487) (17eddd1), closes #1420
- step-functions: support parameters option (#1492) (935054a), closes #1480
- core: construct base class changes (breaking) (#1444) (fb22a32), closes #1431 #1441 #189 #1441 #1431
- core: idiomize cloudformation intrinsics functions (#1428) (04217a5), closes #202
- cloudformation: no more generated attribute types in CFN layer (L1) (#1489) (4d6d5ca), closes #1455 #1406
- cloudformation: stop generating legacy cloudformation resources (#1493) (81b4174)
BREAKING CHANGES TO EXPERIMENTAL FEATURES
- Cross-stack references: if you are using
export()
and import()
to share constructs between stacks, you can stop doing that, instead of FooImportProps
accept an IFoo
directly on the consuming stack, and use that object as usual. ArnUtils.fromComponents()
and ArnUtils.parse()
have been moved onto Stack
.- All CloudFormation pseudo-parameter (such as
AWS::AccountId
etc) are now also accessible via Stack
, as stack.accountId
etc. - All CloudFormation intrinsic functions are now represented as static methods under the
Fn
class (e.g. Fn.join(...)
instead of new FnJoin(...).toString()
) resolve()
has been moved to this.node.resolve()
.CloudFormationJSON.stringify()
has been moved to this.node.stringifyJson()
. validate()
now should be protected
.- The deprecated
cloudformation.XxxResource
classes have been removed. Use the CfnXxx
classes instead. - Any
CfnXxx
resource attributes that represented a list of strings are now typed as string[]
s (via #1144). Attributes that represent strings, are still typed as string
(#712) and all other attribute types are represented as cdk.Token
. - route53: The
route53.TXTRecord
class was renamed to route53.TxtRecord
. - route53: record classes now require a
zone
when created (not assuming zone is the parent construct). - lambda: the static "metric" methods moved from
lambda.FunctionRef
to lambda.Function
. - Many AWS resource classes have been changed to conform to API guidelines:
XxxRef
abstract classes are now IXxx
interfacesXxxRefProps
are now XxxImportProps
XxxRef.import(...)
are now Xxx.import(...)
accept XxxImportProps
and return IXxx
export(): XxxImportProps
is now defined in IXxx
and implemented by imported resources